home *** CD-ROM | disk | FTP | other *** search
/ QuickTime for the Web (2nd Edition) / QuickTime for the Web (2nd Edition).iso / pc / Demos / Mac / Matthew's Behaviors / TrackMatrixƒ / TrackMatrix1.0 < prev   
Encoding:
INI File  |  2001-09-10  |  12.4 KB  |  342 lines

  1. [Name]
  2. TrackMatrix v1.0 - Provides events for positioning tracks
  3. By Matthew Peterson, matthew@pinoko.berkeley.edu
  4.  
  5. [Description]
  6. 2-19-2000
  7. This behavior offers the following 5 functions (Scroll down for a better
  8. description of this behavior):
  9.  
  10. MoveTrackBy :        This event uses 3 Input Global Variables:
  11.                                                                                         TrackIndex -- the index of the track to move
  12.                                                                                                 MoveTrackX -- The amount in the x direction
  13.                                                                                                 MoveTrackY -- The amount in the y direction
  14. MoveTrackTo :        This event uses 3 Input Global Variables:
  15.                                                                                         TrackIndex -- the index of the track to move
  16.                                                                                                 MoveTrackX -- The x location
  17.                                                                                                 MoveTrackY -- The y location 
  18.                                                                                                                     (relative to the track containing this behavior)
  19. TrackLocation :    This event uses 1 Input Global Variable:
  20.                                                                                             TrackIndex -- the index of the track
  21.  
  22.                                                                                                 This event returns 2 Output Global Variables:
  23.                                                                                         MoveTrackX -- The x location
  24.                                                                                                 MoveTrackY  -- The y location
  25.                                                                                                                     (relative to the track containing this behavior)
  26. TrackStatus    :         This event returns 9 Output Global Variables:
  27.                                                                                         NumTracks -- The total number of tracks in the movie
  28.                                                                                              NumVisibleTracks -- The number of visible spatial tracks
  29.                                                                                                 MovieTop -- The relative location of the top of the movie
  30.                                                                                                 MovieBottom -- The relative location of the bottom of the movie
  31.                                                                                                 MovieLeft -- The relative location of the left of the movie
  32.                                                                                                 MovieRight -- The relative location of the right of the movie.
  33.                                                                                                                                                                                                                 i.e. Width of movie = MovieLeft - MovieRight
  34.                                                                                                 MovieFront -- Layer of the top-most track
  35.                                                                                                 MovieBack -- Layer of the bottom-most track
  36.                                                                                                 ReferenceIndex -- Index of sprite track containing this behavior
  37.  
  38. IsTrackVisible :    This event uses 1 Input Global Variable:
  39.                                                                                                 TrackIndex -- the index of the track
  40.  
  41.                                                                                                 This event returns 1 Output Global Variables:
  42.                                                                                                 TrackVisible -- 1 means it exists and is visible
  43.                                                                                                                        0 means it exists and is not visible
  44.                                                                                                                        -1 means it does NOT exist
  45.                                NOTE: visible means it has positive dimensions and is enabled
  46.                                       Non-spatial tracks are not be visible.
  47.  
  48. Currently Quicktime is very limited in its ability to move tracks
  49. around, or to even know where they are. Briefly here are the 
  50. limitations:
  51. 1) There is only a movematrixBy, no movematrixTo
  52. 2) movematrixBy only takes constants, no variables
  53. 3) movematrixBy doesn't work with negative numbers
  54. 4) there are no propertes to find the position of a track
  55. 5) There are no propertis to know how many tracks there are
  56. 6) There are no propertis to know the size of the movie.
  57. 7) No properties to get the index of the current track.
  58.  
  59. This behavior gets around these limitations though matrix rotation
  60. and other tricks.
  61. See Demo Project for examples. Briefly, to use these functions, you
  62. should place this behavior in a sprite on a sprite track that you are
  63. going to use as your reference track. You shouldn't use these functions
  64. to move your reference track. To move other tracks, set the global 
  65. variable, TrackIndex to the index of the track you want to move,
  66. then set the MoveTrackX and MoveTrackY global variables. Finally,
  67. execute the appropriate event, either MoveTrackBy or MoveTrackTo.
  68. For Example, if the behavior is in spriteofid(1), you can move the second 
  69. track by (-5, 12) by saying:
  70.  
  71. TrackIndex = 2
  72. MoveTrackX = -5
  73. MoveTrackY = 12
  74. spriteofid(1).executeevent($MoveTrackBy)
  75.  
  76. Revision History:
  77.  
  78.  
  79. [Parameters]
  80.  
  81. [200030 MoveTrackBy]
  82. GlobalVars TrackIndex MoveTrackX MoveTrackY MP_enabledstatus
  83. //Remember if the track started out enabled so we can restore it later
  84. MP_enabledstatus = TrackOfIndex(TrackIndex).TrackEnabled
  85. IF(MP_enabledstatus)
  86.     //It is faster to move tracks that aren't enabled
  87.     TrackOfIndex(TrackIndex).SetEnabled(FALSE)
  88. ENDIF
  89. //Do we need to move in the X direction?
  90. IF(MoveTrackX ≠ 0)
  91.     ExecuteEvent(200031)
  92. ENDIF
  93. //Do we need to move in the Y direction?
  94. IF(MoveTrackY ≠ 0)
  95.     ExecuteEvent(200032)
  96. ENDIF
  97. //Restore enabled Status
  98. IF(MP_enabledstatus)
  99.     TrackOfIndex(TrackIndex).SetEnabled(TRUE)
  100. ENDIF
  101.  
  102. [200031 MP_MoveTrackByX]
  103. GlobalVars MoveTrackX TrackIndex
  104. // first move in the negative direction by big amounts if needed
  105. // Moving tracks in the negative direction requires rotating the
  106. // The track twice.
  107. IF(MoveTrackX < 0)
  108.     IF(MoveTrackX > -10)
  109.         MoveTrackX = MoveTrackX + 10
  110.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,5,0)
  111.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,0)
  112.     ELSEIF(MoveTrackX > -100)
  113.         MoveTrackX = MoveTrackX + 100
  114.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,50,0)
  115.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,0)
  116.     ELSEIF(MoveTrackX > -500)
  117.         MoveTrackX = MoveTrackX + 500
  118.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,250,0)
  119.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,0)
  120.     ELSE
  121.         MoveTrackX = MoveTrackX + 2000
  122.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,1000,0)
  123.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,0)
  124.     ENDIF
  125. ENDIF
  126. //Now Fine tune the position by moving in the positive direction
  127. //The reason why we need to do these loops is that MoveMatrixBy
  128. //only accepts constants, so we have to loop through preset values.
  129. WHILE (MoveTrackX >= 500)
  130.     MoveTrackX = MoveTrackX - 500
  131.     TrackOfIndex(TrackIndex).MoveMatrixBy(500,0)
  132. ENDWHILE
  133. WHILE (MoveTrackX >= 100)
  134.     MoveTrackX = MoveTrackX - 100
  135.     TrackOfIndex(TrackIndex).MoveMatrixBy(100,0)
  136. ENDWHILE
  137. WHILE (MoveTrackX >= 25)
  138.     MoveTrackX = MoveTrackX - 25
  139.     TrackOfIndex(TrackIndex).MoveMatrixBy(25,0)
  140. ENDWHILE
  141. WHILE (MoveTrackX >= 10)
  142.     MoveTrackX = MoveTrackX - 10
  143.     TrackOfIndex(TrackIndex).MoveMatrixBy(10,0)
  144. ENDWHILE
  145. WHILE (MoveTrackX >= 5)
  146.     MoveTrackX = MoveTrackX - 5
  147.     TrackOfIndex(TrackIndex).MoveMatrixBy(5,0)
  148. ENDWHILE
  149. WHILE (MoveTrackX >= 2)
  150.     MoveTrackX = MoveTrackX - 2
  151.     TrackOfIndex(TrackIndex).MoveMatrixBy(2,0)
  152. ENDWHILE
  153. WHILE (MoveTrackX >= 1)
  154.     MoveTrackX = MoveTrackX -1
  155.     TrackOfIndex(TrackIndex).MoveMatrixBy(1,0)
  156. ENDWHILE
  157.  
  158.  
  159. [200032 MP_MoveTrackByY]
  160. GlobalVars MoveTrackY TrackIndex
  161. //This is the same function as MoveTrackByX but in the Y direction
  162. IF(MoveTrackY < 0)
  163.     IF(MoveTrackY > -10)
  164.         MoveTrackY = MoveTrackY + 10
  165.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,5)
  166.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,0)
  167.     ELSEIF(MoveTrackY > -100)
  168.         MoveTrackY = MoveTrackY + 100
  169.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,50)
  170.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,0)
  171.     ELSEIF(MoveTrackY > -500)
  172.         MoveTrackY = MoveTrackY + 500
  173.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,250)
  174.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,0)
  175.     ELSE
  176.         MoveTrackY = MoveTrackY + 2000
  177.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,1000)
  178.         TrackOfIndex(TrackIndex).RotateMatrixBy(180,0,0)
  179.     ENDIF
  180. ENDIF
  181. WHILE (MoveTrackY >= 500)
  182.     MoveTrackY = MoveTrackY - 500
  183.     TrackOfIndex(TrackIndex).MoveMatrixBy(0,500)
  184. ENDWHILE
  185. WHILE (MoveTrackY >= 100)
  186.     MoveTrackY = MoveTrackY - 100
  187.     TrackOfIndex(TrackIndex).MoveMatrixBy(0,100)
  188. ENDWHILE
  189. WHILE (MoveTrackY >= 25)
  190.     MoveTrackY = MoveTrackY - 25
  191.     TrackOfIndex(TrackIndex).MoveMatrixBy(0,25)
  192. ENDWHILE
  193. WHILE (MoveTrackY >= 10)
  194.     MoveTrackY = MoveTrackY - 10
  195.     TrackOfIndex(TrackIndex).MoveMatrixBy(0,10)
  196. ENDWHILE
  197. WHILE (MoveTrackY >= 5)
  198.     MoveTrackY = MoveTrackY - 5
  199.     TrackOfIndex(TrackIndex).MoveMatrixBy(0,5)
  200. ENDWHILE
  201. WHILE (MoveTrackY >= 2)
  202.     MoveTrackY = MoveTrackY - 2
  203.     TrackOfIndex(TrackIndex).MoveMatrixBy(0,2)
  204. ENDWHILE
  205. WHILE (MoveTrackY >= 1)
  206.     MoveTrackY = MoveTrackY -1
  207.     TrackOfIndex(TrackIndex).MoveMatrixBy(0,1)
  208. ENDWHILE
  209.  
  210.  
  211. [200033 MoveTrackTo]
  212. GlobalVars MP_mx MP_my MP_mx1 MP_my1 MoveTrackX MoveTrackY TrackIndex
  213. //There is no MoveMatrixTo, so we need to invent one. First we find the location
  214. //of the track. LiveStage doesn't give us a function for this, but we can determine
  215. //where the track thinks the mouse is, and then compare that to the location the reference
  216. //track thinks the mouse is. This will give us the locaiton of the track.
  217. //Then we do a MP_trackmoveby by the difference in the final location and the
  218. //current location.
  219. MP_mx = MouseHorizontal
  220. MP_mx1 = TrackOfIndex(TrackIndex).MouseHorizontal
  221. MP_my = MouseVertical
  222. MP_my1 = TrackOfIndex(TrackIndex).MouseVertical
  223.  
  224. MP_mx =  MoveTrackX - (MP_mx - MP_mx1)
  225. MP_my =  MoveTrackY - (MP_my - MP_my1)
  226. MP_mx1 = MoveTrackX
  227. MP_my1 = MoveTrackY
  228. MoveTrackX = MP_mx
  229. MoveTrackY = MP_my
  230. //Now that we know how much to move by, perform the moveby event:
  231. SpriteOfID($thisSpriteID).ExecuteEvent(100030)
  232.  
  233. [200034 TrackLocation]
  234. GlobalVars MP_mx MP_my MP_mx1 MP_my1 MoveTrackX MoveTrackY TrackIndex
  235. //LiveStage doesn't give us a function for track location, but we can determine
  236. //where the track thinks the mouse is, and then compare that to the location the reference
  237. //track thinks the mouse is. This will give us the locaiton of the track.
  238. MP_mx = MouseHorizontal
  239. MP_mx1 = TrackOfIndex(TrackIndex).MouseHorizontal
  240. MP_my = MouseVertical
  241. MP_my1 = TrackOfIndex(TrackIndex).MouseVertical
  242.  
  243. MoveTrackX = (MP_mx - MP_mx1)
  244. MoveTrackY = (MP_my - MP_my1)
  245.  
  246.  
  247. [200035 TrackStatus]
  248. GlobalVars NumTracks NumVisibleTracks MovieTop MovieBottom MovieLeft MovieRight MovieFront MovieBack ReferenceIndex  MP_mx MP_my MP_mx1 MP_my1 
  249. LocalVars MP_tempvalue MP_TempLayer MP_GotIndex 
  250. //Call this event to update movie and track parameters.
  251. //Initialize the variables:
  252. MP_tempvalue = 0
  253. MP_GotIndex = FALSE
  254. NumVisibleTracks = 0
  255. NumTracks = 1
  256. MovieTop = 0
  257. MovieBottom=0
  258. MovieLeft=0
  259. MovieRight=0
  260. MovieFront = TrackLayer
  261. MovieFront = TrackLayer
  262. WHILE(MP_tempvalue ≠ 314)
  263.     //first set tempvalue to something, because if the track doesn't exist, the value won't be
  264.     //updated.
  265.     MP_tempvalue  = 314
  266.     MP_tempvalue  = TrackOfIndex(NumTracks).TrackEnabled
  267.     IF(MP_tempvalue  ≠ 314)//track exists.
  268.         IF(MP_tempvalue AND TrackOfIndex(NumTracks).TrackWidth AND TrackOfIndex(NumTracks).TrackHeight)
  269.             //Find the location of the track
  270.             NumVisibleTracks = NumVisibleTracks + 1
  271.             MP_mx = MouseHorizontal
  272.             MP_mx1 = TrackOfIndex(NumTracks).MouseHorizontal
  273.             MP_my = MouseVertical
  274.             MP_my1 = TrackOfIndex(NumTracks).MouseVertical
  275.             MP_mx =  MP_mx - MP_mx1 //x location of the track
  276.             MP_my =  MP_my - MP_my1 //y location of track
  277.             //See if this is our this track's index or not:
  278.             IF(NOT MP_GotIndex)
  279.                 // First see if the dimensions match
  280.                 IF(NOT MP_mx AND NOT MP_my AND (TrackOfIndex(NumTracks).TrackHeight = TrackHeight))
  281.                     //Now, to make sure, move the layer of one track and see if the other also moves
  282.                     MP_TempLayer = TrackOfIndex(NumTracks).TrackLayer
  283.                     TrackOfIndex(NumTracks).SetLayerTo(MP_TempLayer + 5)
  284.                     IF(TrackLayer = MP_TempLayer + 5)
  285.                         ReferenceIndex = NumTracks //This is our track!
  286.                         MP_GotIndex = TRUE
  287.                     ENDIF
  288.                     TrackOfIndex(NumTracks).SetLayerTo(MP_TempLayer) //Now restore the layer.
  289.                 ENDIF    
  290.             ENDIF
  291.             //Find the maximum dimensions
  292.             IF(MovieLeft > MP_mx)
  293.                 MovieLeft = MP_mx
  294.             ENDIF
  295.             IF(MovieRight < MP_mx + TrackOfIndex(NumTracks).TrackWidth)
  296.                 MovieRight = MP_mx+ TrackOfIndex(NumTracks).TrackWidth
  297.             ENDIF
  298.             IF(MovieTop > MP_my)
  299.                 MovieTop = MP_my
  300.             ENDIF
  301.             IF(MovieBottom < MP_my + TrackOfIndex(NumTracks).TrackHeight)
  302.                 MovieBottom = MP_my+ TrackOfIndex(NumTracks).TrackHeight
  303.             ENDIF
  304.             //Find Frontmost and backmost layers
  305.             IF(MovieFront > TrackOfIndex(NumTracks).TrackLayer)
  306.                 MovieFront = TrackOfIndex(NumTracks).TrackLayer
  307.             ELSEIF(MovieBack < TrackOfIndex(NumTracks).TrackLayer)
  308.                 MovieBack = TrackOfIndex(NumTracks).TrackLayer
  309.             ENDIF
  310.             
  311.         ENDIF
  312.         NumTracks = NumTracks + 1
  313.     ELSE
  314.         NumTracks = NumTracks - 1 //went too far. go back one.
  315.     ENDIF
  316. ENDWHILE
  317.  
  318. [200036 IsTrackVisible]
  319. GlobalVars TrackVisible  TrackIndex
  320. LocalVars MP_tempvalue
  321. //Checks whether or not track of index TrackIndex exists and is visible
  322. //Returns results in Global Variable TrackVisible. 
  323. // -1 means it doesn't exist. 1 means exists and is visible, 0 means exists but not visible
  324. MP_tempvalue  = 314
  325. MP_tempvalue  = TrackOfIndex(TrackIndex).TrackEnabled
  326. IF(MP_tempvalue  ≠ 314)//track exists.
  327.     IF(MP_tempvalue AND TrackOfIndex(TrackIndex).TrackWidth AND TrackOfIndex(TrackIndex).TrackHeight)
  328.         TrackVisible = TRUE  //track is visible
  329.     ELSE
  330.         TrackVisible = 0 //Track is not visible
  331.     ENDIF
  332. ELSE
  333.     TrackVisible = -1 //Track doesn't exist
  334. ENDIF
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.